<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >

      <el-table-column align="left" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="员工ID" width="110" align="left">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="110" align="left">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="电话号码" width="110" align="left">
        <template slot-scope="scope">
          {{ scope.row.tel }}
        </template>
      </el-table-column>

      <el-table-column class-name="status-col" label="未带口罩次数" width="110" align="left">
        <template slot-scope="scope">
          <el-tag :type="scope.row.no_mask_count | statusFilter">{{ scope.row.no_mask_count }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getNoMaskInfo } from '@/api/nomask'
export default {
  filters: {
    statusFilter(no_mask_count) {
      var status = 'success'
      if (no_mask_count > 6) {
        status = 'danger'
      }
      if (no_mask_count > 3 && no_mask_count < 7) {
        status = 'warning'
      }
      //   const statusMap = {
      //     published: 'success',
      //     draft: 'gray',
      //     deleted: 'danger'
      //   }
      //    statusMap[status]
      return status
    }
  },
  data() {
    return {
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 从后台返回数据
    fetchData() {
      debugger
      this.listLoading = true
      console.log(getNoMaskInfo())

      // 调用API访问数据
      getNoMaskInfo().then(response => {
        console.log('从后台搬运数据成功')
        this.list = response.data.items
        this.listLoading = false
      })
    }
  }
}
</script>
